package com.eight.travel.controller;

import com.eight.travel.pojo.User;
import com.eight.travel.service.HotelService;
import com.eight.travel.service.OrderRoomService;
import com.eight.travel.utils.BaseResp;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/hotel")
//@CrossOrigin
public class HotelController {
    @Autowired
    HotelService hotelService;
    @Autowired
    OrderRoomService orderRoomService;
    @ApiOperation(value = "模糊查询某个城市的酒店")

    @RequestMapping(value = "/finBylike", method = RequestMethod.GET)
    public BaseResp finBylike(String byname){
        //照片,名字,等级
        System.out.println("byname ============= " + byname);
        BaseResp all = hotelService.findbylike(byname);
        return all;
    }

    @RequestMapping(value = "/findAll", method = RequestMethod.GET)
    public BaseResp findAll(){
        BaseResp all = hotelService.findAll();
        //照片,名字,等级
        return all;
    }
    //基本路径传参,热度查询
    @ApiOperation(value = "热度查询")
    @RequestMapping(value = "/hot/{address}", method = RequestMethod.GET)
    public BaseResp hotelhot(@ApiParam("对应城市的地址")@PathVariable("address") String address){
        BaseResp all = hotelService.finhotelhot(address);
        //名字,地址,热度,等级,照片
        return all;
    }
    //星级查询
    @RequestMapping(value = "/start/{start}/{address}", method = RequestMethod.GET)
    public BaseResp hotelstart(@ApiParam("等级")@PathVariable("start") int start,@ApiParam("地址")@PathVariable("address") String address){
        BaseResp all = hotelService.finhotelstart(address,start);
        return all;
    }
    //价格查询
    @RequestMapping(value = "/price", method = RequestMethod.GET)
    public BaseResp hotelprice(String address){
        BaseResp all = hotelService.findhotelprice(address);
        //名字,等级,热度,地址,价格
        return all;
    }
    //退房业务
    @ApiOperation(value = "退房业务,失败事务回滚")
    @RequestMapping(value = "/outroom", method = RequestMethod.GET)
    public BaseResp hoteloutroom(Integer uid,String number){
        BaseResp all = hotelService.outroom(uid,number);
        return all;
    }
    //优惠
    @ApiOperation(value = "老用户优惠百分之八十")
    @RequestMapping(value = "/youhui/{uid}/{address}", method = RequestMethod.GET)
    public BaseResp youhui(@ApiParam("uid=2")@PathVariable("uid") Integer uid,@ApiParam("地址西安")@PathVariable("address") String address){
        BaseResp all = hotelService.youhui(uid, address);
        return all;
    }
    //查看酒店评论
    @RequestMapping(value = "/viewcom/{hid}", method = RequestMethod.GET)
    public BaseResp ViewCommens(@ApiParam("hid=1")@PathVariable("hid") Integer hid){
        BaseResp baseResp = hotelService.ViewCom(hid);
        return baseResp;
    }
    //提交评论
    @ApiOperation(value = "联合查询,提交评论")
    @RequestMapping(value = "/subcom/{hid}", method = RequestMethod.GET)
    public BaseResp subCom(String com,@ApiParam("hid=1")@PathVariable("hid") Integer oid){
        BaseResp baseResp = hotelService.subCom(com, oid);
        return baseResp;
    }
    //抢购最后一间房
    @ApiOperation(value = "并发问题/最后一间房多个用户同时抢购")
    @RequestMapping(value = "/qgenroom/{hid}", method = RequestMethod.GET)
    public BaseResp qg(@ApiParam("传入用户集合") List<User> user,@ApiParam("酒店id=1")@PathVariable("hid") Integer hid){
        BaseResp qgendroom = orderRoomService.qgendroom(user, hid);
        return qgendroom;

    }
}
